package com.dts.backproject.controller;

import com.dts.backproject.entity.po.Message;
import com.dts.backproject.entity.po.Result;
import com.dts.backproject.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/post")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @GetMapping("/all")
    public List<Message> selectAllMessage(){
        return messageService.findAll();
    }

    @PostMapping(value = "/add")
    public Result selectAllMessage(@RequestParam(value = "email", required = false) String email, @RequestBody Message message){
        messageService.saveMessage(email, message);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable String id, @RequestParam String email){
        messageService.deleteById(id, email);
        return Result.success();
    }
}
